﻿using System.Web.Security;
using MMSWebsite.HtmlHepler;
using MMSWebsite.Models;
using BusinessLibrary;

namespace MMSWebsite.DataAccessManagement
{

    public class AccountProvider
    {
        EmployeeAccessProvider _empProvider = new EmployeeAccessProvider();
        

        public bool Login(Account account)
        {
            var emp = _empProvider.GetEmployeeByCode(account.Username);
            if (emp == null) return false;
            else
            {
                if (!MD5Security.VerifyMd5Hash(account.Password, emp.Employee.Password))
                {
                    return false;
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(emp.Employee.Code, account.RememberMe);
                    return true;
                }
            }
        }

        public void LogOut()
        {
            FormsAuthentication.SignOut();
        }

     

    }
}